<%--
/***********************************************
* 파일명 : attendFinish.jsp
* 기  능 : 근태관리 메인 화면
* 최초 작성일 : 2009/04/14
* @author : Yang Chang Hwan
*************************************************/
--%>

<%@ page 	language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib 	prefix="s" 		uri="/struts-tags"%>
<%@ page import="attend.com.CodeMetrix"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<s:head theme="ajax" />
	
	<meta http-equiv="Content-Type" 	content="text/html; charset=UTF-8" />
	<meta http-equiv="pragma" 			content="no-cache" />
	<meta http-equiv="cache-control" 	content="no-cache" />
	<meta http-equiv="expires" 			content="0" />
	
	<title>근태관리 마감</title>
	
	<script type="text/javascript" >

	/*********************************************CALENDER******************************************************/
	/////////////////////달력////////////////////////////////////////////////
	function doOnLoad()
	{
		// 달력
		cal1 = new dhtmlxCalendarObject('s_date', false, {isYearEditable: true , isMonthEditable : true});
		cal1.setYearsRange(2000, 2050);
		cal1.setPosition(20,-82);
		cal1.draw();
		cal1.setOnClickHandler(selectDate1);

		cal2 = new dhtmlxCalendarObject('e_date', false, {isYearEditable: true , isMonthEditable : true});
		cal2.setYearsRange(2000, 2050);
		cal2.setPosition(20,-82);
		cal2.draw();
		cal2.setOnClickHandler(selectDate2);

		document.getElementById('s_date').onfocus = function() { if (cal2.isVisible()) cal2.hide(); }
		document.getElementById('e_date').onfocus = function() { if (cal1.isVisible()) cal1.hide(); }

		document.body.onclick = function(){calendarHide("cal1,cal2","D");};
	}

	function selectDate1(date)
	{
		document.getElementById('s_date').value = cal1.getFormatedDate(null,date);
		dateFrom 	= new Date(date);
		dateTo 		= null;
		cal2.setSensitive(dateFrom, dateTo);
		cal1.hide();
		return true;
	}

	function selectDate2(date)
	{
		document.getElementById('e_date').value = cal1.getFormatedDate(null,date);
		dateTo 		= new Date(date);
		dateFrom 	= null;
		cal1.setSensitive(dateFrom, dateTo);
		cal2.hide();
		return true;
	}
	/////////////////////달력////////////////////////////////////////////////
	/*********************************************CALENDER******************************************************/

		var args	=	"";

		//체크된 값들만 모아 배열 메트릭스 구성
		function fnc_arrMetrix() {
	
			//1개일경우
			if (frm.s_chk.length == undefined ) {
				if (frm.s_chk.checked) {
					//초기화
					args = 	new Array();	//배열생성
	
					var arr = new Array();
					
					//pk
					arr.push(	frm.yyyymmdd.value		);
					//pk
					
					args.push( arr );
				}
				
			} else {	//다수일 경우
				//초기화
				args = 	new Array();	//배열생성
				
				for (var i = 0 ; i < frm.s_chk.length ; i++ ) {
					
					if ( frm.s_chk[i].checked ) {
	
						var arr	=	new Array();
					
						//arr.push(	frm.s_chk[i].value			);
	
						//pk
						arr.push(	frm.yyyymmdd[i].value		);
						//pk
						
						args.push( arr );
	
					}	//if
					
				}	//for
			}
	
			return args;
		}	//fnc_arrMetrix end.........
		
		//전체선택 /해제
		function fnc_selectAll(f) {
			if ( typeof frm.s_chk != "undefined" ) {
				
				if (f.confirm_yn.value == "N" || f.close_yn == "N") {
					f.selectALL.checked = false;
					return false;
				}
				
				if ( typeof frm.s_chk.length != "undefined") {

					if ( f.selectALL.checked ) {

						var CheckCount = 0;
						
						for ( var i = 0 ; i < frm.s_chk.length ; i++ ) {
							if (!frm.s_chk[i].disabled) {
								frm.s_chk[i].checked = true;
								CheckCount += 1;
							}
						}

						if (CheckCount == 0) {
							f.selectALL.checked = false;
							alert("선택할 항목이 없습니다.");
							return false;
						}
						
					} else {
						for ( var i = 0 ; i < frm.s_chk.length ; i++ )  frm.s_chk[i].checked = false;
					}			
				} else {
					if ( f.selectALL.checked ) {
								frm.s_chk.checked = true;
					} else {						 
						frm.s_chk.checked = false;
					}	
				}
			} else {
				if(f.selectALL.checked){
					alert("체크할 데이타가 없습니다.");
					 f.selectALL.checked = false;
				}
			}
		}	//전체선택

		//마감처리
		function fnc_finish(f) {

			if (!f.s_chk) {
				alert("체크할 데이터가 없습니다.");
			}

			var chk = document.getElementsByName("s_chk");

			var CheckCount = 0;

			if (chk.length == 1) {
				if (chk(i).checked) { 
					if (f.close_yn.value == "Y") {
						chk(i).checked = false;
						//CheckCount -= 1;
					}
				}
			} else {
				for (i = 0; i < chk.length; i++) {
					if (chk(i).checked) { 
						if (f.close_yn[i].value == "Y") {
							chk(i).checked = false;
							//CheckCount -= 1;
						}
					}
				}
			}

			//count
			for ( var i = 0; i < chk.length; i++) {
				if (chk(i).checked) { 
					CheckCount++;
				}
			}
			
			if (CheckCount < 1) {
				f.selectALL.checked = false;
				alert("이미 마감된 항목은 제외합니다.\n\n선택한 항목이 없습니다.");
				return false;
			} else {
				if ( confirm("이미 마감된 항목은 제외합니다.\n\n근태마감을 하시겠습니까?") ) {

					f.updateArgs.value = fnc_arrMetrix();	//update 할 arguments 전달
					
					//CRUD
					f.crud.value 		= "<%= CodeMetrix.INSERT %>";
					
					f.ajaxFlag.value 	= "Y";
					
					dojo.event.topic.publish("ajaxDojo");

					return false;
				}
			}
			
			return false;
		}
		
		//마감취소-삭제
		function fnc_cancel(f) {

			if (!f.s_chk) {
				alert("조회된 데이터가 없습니다.");
			}

			var chk = document.getElementsByName("s_chk");

			var CheckCount = 0;

			if (chk.length == 1) {
				if (chk(i).checked) { 
					if (f.close_yn.value == "N") {
						chk(i).checked = false;
					}
				}
			} else {

				for (var i = 0; i < chk.length; i++) {
					if (chk(i).checked) { 
						if (f.close_yn[i].value == "N") {
							chk(i).checked = false;
						}
					}
				}	//for
			}
			
			

			//count
			for ( var i = 0; i < chk.length; i++) {
				if (chk(i).checked) { 
					CheckCount++;
				}
			}
			
			if (CheckCount < 1) {
				f.selectALL.checked = false;
				alert("확인완료 되지 않은 항목은 제외합니다.\n\n선택한 항목이 없습니다.");
				return false;
			}
			
			if (confirm("마감을 취소하시겠습니까?")) {

				f.updateArgs.value = fnc_arrMetrix();	//update 할 arguments 전달
				
				//CRUD
				f.crud.value 		= "<%= CodeMetrix.DELETE %>";
				
				document.getElementById("ajaxFlag").value = "DELETE";

				f.ajaxFlag.value 	= "Y";

				dojo.event.topic.publish("ajaxDojo");

				return false;
			}
			return false;
		}

		//마감일자 클릭시 팝업창을 띄운다.
		function fnc_attendManager(d) {
			//alert(d + "\n\n마감일자 클릭시 팝업창을 띄운다.");

			var w 		= 853;
			var h 		= 562;
			
			var x 		= 	fnc_center_x(w);
			var y 		= 	fnc_center_y(h);

			var url 	= 	"attendFinish_manager_p.action";
			var nm 		= 	"detail";
			var attr 	= 	"width=" + w + " , height=" + h + " , top=" + y + " , left=" + x + " , status=no , scrollbars=yes";   //window size
			
			var param	=	"one_yyyymmdd=" + d;
			
				url		+=	"?" + param;

			window.open(url , nm , attr);
			
			return false;
		}

		//popup 정가운데 띄우기
		function fnc_center_x(w) {

	       	var x;
	       	
			x =  (screen.availWidth - w) / 2;

	       	return x;
		}

	  	//popup 정가운데 띄우기
		function fnc_center_y(h) {

	       	var y;
	       	
			y =  (screen.availHeight - h) / 2;

	       	return y;
		}

		function selectIdenty(){

			$("#identy_yn").css({backgroundColor:'#3366FF', color:'#FFFFFF'});
	    	  if($("#identy_yn").val()=="ALL"){
	    		  $("#identy_yn").css({backgroundColor:'#ffffff',color:'#656464'});
	    	  }
		}

		function selectFinish(){

			$("#finish_yn").css({backgroundColor:'#3366FF', color:'#FFFFFF'});
	    	  if($("#finish_yn").val()=="ALL"){
	    		  $("#finish_yn").css({backgroundColor:'#ffffff',color:'#656464'});
	    	  }
		}
	</script>

</head>

<body onload="doOnLoad()">
	<!--------- Contants Range : STR--------------->
	<div class="fl_ri">
		<div id="contants_box">
			<div id="tit">  
				<span class="fl_ri tit_navi">Home &gt;  관리자 &gt; <span class="f_b">근태마감</span><img src="/images/btl_navi.gif" class="img_tp" /></span>
				<div class="fl_le"><img src="/images/tit_menu05_img06.gif" /></div>
			</div>
			<s:form theme="simple"  name="frm" id="frm">
				<s:hidden value="msg" />
				<!-- 데이터 체크 결과 및 업데이트 결과를 담고 있는 변수 -->
				
				<s:hidden id="cur_page" name="cur_page"/><!-- 현 페이지 번호 -->
				<!----------Search_Box : STR ---------->
				<div id="search01">
					<div id="search_box01">
						<ul>
							<li class="txt">기간</li>
							<li class="input">
								<!-- /////////////////////달력//////////////////////////////////////////////// -->
	                              <input type="text" size="12" maxlength="10" name="s_date" id="s_date" value="<s:property value="s_date" />" class="input_80se" style="height:20;background-image:url('images/calendar/calendar.gif');background-repeat:no-repeat;background-position:right 2px;cursor:hand">
	                               ~
	                              <input type="text" size="12" maxlength="10" name="e_date" id="e_date" value="<s:property value="e_date" />" class="input_80se" style="height:20;background-image:url('images/calendar/calendar.gif');background-repeat:no-repeat;background-position:right 2px;cursor:hand">
	                            <!-- /////////////////////달력//////////////////////////////////////////////// -->
							</li>
							<li class="txt01">확인여부</li>
							<li class="input">
								<s:select id="identy_yn" 		name="identy_yn" 		list="#{'Y':'Y' , 'N':'N'}" cssClass="combobox100sel" headerKey="ALL" headerValue="::전체::" onchange="return selectIdenty()"/>
							</li>
							<li class="txt01">마감여부</li>
							<li class="input">
								<s:select id="finish_yn" 		name="finish_yn" 		list="#{'Y':'Y' , 'N':'N'}" cssClass="combobox100se" headerKey="ALL" headerValue="::전체::" onchange="return selectFinish()"/>
							</li>
						</ul>
						<ul><li>&nbsp;</li></ul>
						<ul class="cebtn">
							<span class="fl_ri">
								<img src="/images/btn_search.gif" style="vertical-align: middle;cursor:pointer;"  onclick="return getList('search')" />
								<s:submit type='image' onclick="return fnc_finish(this.form)" 	src="/images/btn_finish.gif" 	cssClass="img_tm" title="마감" value="마감" />
								<s:submit type='image' onclick="return fnc_cancel(this.form)" 	src="/images/btn_cancel01.gif" 	cssClass="img_tm" title="마감취소" value="마감취소" />
							</span>
						</ul>
						
					</div>
				</div>	
				
				<!----------Search_Box : ENd ---------->  
				<!-- ajax로 데이터를 조회해 온다. -->
				<s:url id="ajax_list"  action="attend_finish_list_ajax" />
				<s:div id="itemAmtlistDiv" theme="ajax" executeScripts="true" showLoadingText="false" href="%{ajax_list}" listenTopics="ajax_list" formId="frm" />
	
				<s:hidden id="crud" 		name="crud"			/>
				<s:hidden id="updateArgs" 	name="updateArgs"	/>
				<s:hidden id="ajaxFlag" 	name="ajaxFlag" 	/><!-- 확인버튼 클릭시 전체 리플러쉬 없앰 -->
			</s:form>
			<!-- ajax dummy -->
			<s:url id="temp_list"  action="attend_close_update_insert" />
			<s:div id="tempDiv" theme="ajax" executeScripts="true" showLoadingText="false" href="%{temp_list}" listenTopics="ajaxDojo" formId="frm" />
		</div>
	</div>
</body>
</html>